##### My (demuredemeanor) bashrc sub source alias script
# Uses tabstop=4; shiftwidth=4 tabs; foldmarker={{{,}}};
# https://notabug.org/demure/dotfiles/
# legacy repo http://github.com/demure/dotfiles
# vim:set syntax=sh:

### Misc Aliases ### {{{
## Remove OS X 'junk' files
alias rmds='find . -name ".DS_Store" -depth -exec rm -i {} \;'
alias rmd_='find . -iname '._*' -exec rm -rf {} \;'

## Show ls -R with readable depth
## From http://xmodulo.com/useful-bash-aliases-functions.html
alias filetree="ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'"

## List programs connected to network
## From http://xmodulo.com/useful-bash-aliases-functions.html
alias listen="lsof -P -i -n"

## Make ed more usable, command mode is now ':' like vi
alias ed='ed -p:'

## Delete duplicate lines from file name augment
alias deldup="awk '!x[$0]++' "

## Shortcut for wicd-curses
alias wic='wicd-curses'
### End Misc Aliases ### }}}

### rsync Aliases ### {{{
## Old rsync alias
alias rsy='rsync -avrSPXRh'
## Good for sending dirs from server to remote server
alias rsy1='rsync -avSPRh'
## This one is for copying off the network shares.
alias rsy2='rsync -rltDvSPRh'
### End rsync Aliases ### }}}

### rename utils Aliases ### {{{
if [[ $(command -v qmv) ]]; then
    ## Makes qmv more usable, and regex-able
    alias qm='qmv --format=destination-only'
fi
### End rename utils Aliases ### }}}

### pinfo ### {{{
if [[ $(command -v pinfo) ]]; then
    ## Use color pinfo instead of info
    alias info='pinfo'
fi
### End pinfo ### }}}

### Git Aliases ### {{{
alias git_force_reset='git fetch --all && git reset --hard origin/master'
### End Git Aliases ### }}}

### Docker ### {{{
if [[ $(command -v docker) ]]; then
    ## find last docker container
    alias dl='docker ps -l -q'
fi
### End Docker ### }}}

### Vim Aliases ### {{{
if [[ $(command -v vim) ]]; then
    ## set vi to call vim
    alias vi='vim'

    ## Preserve user conf while sudoing vim
    alias svi='sudo -E vim'
fi
### End Vim Aliases ### }}}

### mpv Aliases ### {{{
if [[ $(command -v mpv) ]]; then
    ## set vi to call vim
    alias mp='mpv'
    alias qmp='tsp mpv'
fi
### End mpv Aliases ### }}}

### xclip Aliases ### {{{
if [[ $(command -v xclip) ]]; then
    ## make piping to clipboard simple
        alias xc="xclip -selection c"
fi
### End xclip Aliases ### }}}

### ls Color Test ### {{{
## Tries home cut down on possible large dirs
ls --color=auto ${HOME} &>/dev/null
if [ ${PIPESTATUS[-1]} == 0 ]; then
    alias ls='ls --color=auto'
fi
### End ls Color Test ### }}}

### Update All opkg ### {{{
## Tries home cut down on possible large dirs
## TODO: move to awk
if [[ $(command -v opkg) ]]; then
    ## This is useful on systems like openwrt
    alias opkgup="eval \$(opkg list_installed | sed 's/ - .*//' | sed 's/^/opkg upgrade /')"
fi
### End Update All opkg ### }}}

### bboard alias ### {{{
if [[ $(command -v bboard) ]]; then
    ## lazy alias for sdf's bboard
    alias bb='bboard'
fi
### End board alias ### }}}

### sudo preserve ENV ### {{{
if [ -e "${HOME}/.config/dotconf/sudo_preserve" ]; then
    alias sudo='sudo -E'
fi
### End sudo preserve ENV ### }}}
